package com.efast.dmom.mgmt.controller.les;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.efast.cafe.framework.bean.ResultBean;
import com.efast.cafe.framework.util.SpringWebUtils;
import com.efast.dmom.mgmt.bean.les.TtWhmCountDetailBean;
import com.efast.dmom.mgmt.entity.les.TtWhmCountDetail;
import com.efast.dmom.mgmt.service.les.TtWhmCountDetailService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 盘点明细表 前端控制器
 * </p>
 *
 * @author ChenLiPeng
 * @since 2018-06-12
 */
@Controller
@RequestMapping("/ttWhmCountDetail")
@Api(description = "盘点明细")
public class TtWhmCountDetailController {

	/**
	 * 盘点明细
	 */
	private final TtWhmCountDetailService ttWhmCountDetailService;

	@Autowired
	public TtWhmCountDetailController(TtWhmCountDetailService ttWhmCountDetailService) {
		this.ttWhmCountDetailService = ttWhmCountDetailService;
	}

	/**
	 *
	 * @param ttWhmCountDetailBean
	 *            ttWhmCountDetailBean
	 */
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	@ApiOperation(value = "【新增的接口-库存链接】", notes = "请求参数：")
	public @ResponseBody ResultBean add(@RequestBody TtWhmCountDetailBean ttWhmCountDetailBean) {
		ResultBean result = new ResultBean(true, "'");
		List<TtWhmCountDetail> list = ttWhmCountDetailBean.getTtWhmCountDetailBean();
		List<TtWhmCountDetail> list1 = new ArrayList<>();
		for (TtWhmCountDetail ttWhmCountDetail : list) {
			ttWhmCountDetail.setCreateTime(new Date());
			ttWhmCountDetail.setCreateUser(SpringWebUtils.getRequestUser());
			ttWhmCountDetail.setCompanyCode(SpringWebUtils.getRequestCompany());
			ttWhmCountDetail.setMarkStatus(1);
			list1.add(ttWhmCountDetail);
		}
		ttWhmCountDetailService.insertBatch(list1, list1.size());
		return result;
	}

	/**
	 *
	 * @param ttWhmCountDetail
	 *            ttWhmCountDetail
	 */
	@RequestMapping(value = "/addDetail", method = RequestMethod.POST)
	@ApiOperation(value = "【新增的接口】", notes = "请求参数：")
	public @ResponseBody ResultBean addDetail(@RequestBody TtWhmCountDetail ttWhmCountDetail) {
		ResultBean result = new ResultBean(true, "'");
		ttWhmCountDetail.setCountStatus("0");
		ttWhmCountDetail.setCreateTime(new Date());
		ttWhmCountDetail.setCreateUser(SpringWebUtils.getRequestUser());
		ttWhmCountDetail.setCompanyCode(SpringWebUtils.getRequestCompany());
		ttWhmCountDetail.setMarkStatus(1);
		ttWhmCountDetailService.insert(ttWhmCountDetail);
		return result;
	}

}
